export default {
	data() {
		return {
			videoId: '',
			videoPlaytime: [],
			duration:''
		};
	},
	methods: {
		handlePlay(e) {
			let vid = e.currentTarget.id;

			this.videoId = vid;
			this.videoContext = uni.createVideoContext(vid, this);
			this.videoContext.requestFullScreen({ direction: 90 });
			let videoPlaytime = this.videoPlaytime;
			// console.log('所有播放数据的数组', videoPlaytime);
			let videoItem = videoPlaytime.find(item => item.vid == vid);
			// console.log('上次播放的数据', videoItem);

			if (videoItem) {
				this.videoContext.seek(videoItem.currentTime);
			} else {
				this.videoContext.play();
			}

		},
		handleUpdate(e) {
			// console.log(e);
			let videoObj = {
				vid: e.currentTarget.id,
				currentTime: e.detail.currentTime
			};

			let videoPlaytime = this.videoPlaytime;
			// 判断videoPlaytime 之前有没有记录过当前视频的播放数据
			let videoItem = videoPlaytime.find(item => item.vid == videoObj.vid);

			if (videoItem) {
				videoItem.currentTime = e.detail.currentTime;
			} else {
				videoPlaytime.push(videoObj);
			}

			this.videoPlaytime = videoPlaytime;



		},
		handleEnded(e) {
			let vid = e.currentTarget.id;
			let videoPlaytime = this.videoPlaytime;
			let index = videoPlaytime.findIndex(item => item.vid === vid);
			videoPlaytime.splice(index, 1);
			this.videoPlaytime = videoPlaytime;


		},
		getVideoLength(e) {
			e.detail.duration = parseInt(e.detail.duration);
			//处理时间格式并存放到data中

			this.duration = parseInt(e.detail.duration / 60) + ':' + e.detail.duration % 60;
			// console.log(this.duration);

		}

	}
};
